Skip to content

ir-gen: Fix ICE when reading an indexed ref mut array element#7644

Open
Dnreikronos wants to merge 3 commits into
FuelLabs:masterfrom
Dnreikronos:fix/index-read-ref-mut-array-7602
Open

ir-gen: Fix ICE when reading an indexed ref mut array element#7644
Dnreikronos wants to merge 3 commits into
FuelLabs:masterfrom
Dnreikronos:fix/index-read-ref-mut-array-7602

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

Closes #7602

Reading an element of a ref mut array argument, like self[i] inside an impl ... for [T; N] method, crashed the compiler. A ref mut argument is already a pointer in IR, and the argument gets stored into a local on entry, so by the time the index-read code runs the prefix is a pointer to a pointer to the array. That shape wasn't handled and fell into a todo!(). Writing through the same self[i] worked because the reassignment path already dereferences ref mut arguments.

The index-read path now peels off the extra pointer indirection before indexing, the way reassignment does, and the previously disabled assert_eq(self[i], default) line in the const-generics reassignment test is back on.

A `ref mut` array argument is a pointer in IR, and storing it into a
local adds another level of indirection, so the index-read path saw a
pointer to a pointer to the array and aborted with `todo!()`. Peel the
extra pointer levels before indexing, matching how the reassignment
path already dereferences `ref mut` arguments.

Closes FuelLabs#7602
@Dnreikronos Dnreikronos requested a review from a team as a code owner May 28, 2026 20:22
@fuel-cla-bot
Copy link
Copy Markdown

fuel-cla-bot Bot commented May 28, 2026

Thanks for the contribution! Before we can merge this, we need @Dnreikronos to sign the Fuel Labs Contributor License Agreement.

@cursor
Copy link
Copy Markdown

cursor Bot commented May 28, 2026

PR Summary

Medium Risk
Touches core expression lowering for all index reads; behavior change is narrow (extra loads for multi-level pointers) but mistakes could affect indexing correctness.

Overview
Fixes a compiler ICE when reading through an index on a ref mut array prefix (e.g. self[i] in impl ... for [T; N]). IR lowering left an extra level of indirection on the prefix compared to the reassignment path, which hit todo!() for typed-pointer array indexing.

compile_indexing now loads through nested pointer/reference layers until the prefix points at the real array or slice, then dispatches as before. Unsupported pointer shapes return an internal compile error instead of panicking.

The const-generics reassignment e2e test re-enables assert_eq(self[i], default) that was blocked on this bug.

Reviewed by Cursor Bugbot for commit b863ab9. Bugbot is set up for automated code reviews on this repo. Configure here.

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

@ironcev, can we re-trigger the cla pipe here and on the other PRs that I have open?

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 1, 2026

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing Dnreikronos:fix/index-read-ref-mut-array-7602 (b863ab9) with master (ac933ff)

Open in CodSpeed

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b863ab9. Configure here.

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

@ironcev ready for a look now that CLA's green. The fix lives in compile_indexing: it loads through the nested pointer layers on a ref mut array prefix before dispatching, instead of hitting the todo!() for typed-pointer array indexing. I re-enabled the assert_eq(self[i], default) in the const-generics e2e test. Main thing to sanity-check is whether the extra loads are right across all the pointer shapes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler ICE when accessing self[i] where self is defined using const generics [T;N]

1 participant